#ifndef _CUSTOMWIDGETS_H
#define	_CUSTOMWIDGETS_H

using namespace std;

#include <QTableWidgetItem>
#include <QPushButton>
#include <QLineEdit>
#include <QX11Info>

#include <edgy/edgy.h>

/**
 * This is a basic QPushButton that stores the information about the captured
 * keys.
 */
class KeyPushButton : public QPushButton {
public:
  KeyPushButton(QWidget* parent);
  
  /**
   * Saves the given keys. Should only need to pass 1-3 keys.
   * @param keys list of key names without the XC_ prefix.
   */
  void setKeys(const QStringList keys);
  /**
   * Returns a list of key names.
   */
  QStringList getKeys();
  
private:
  QStringList keys;
  QWidget* parent;
};

/**
 * This is a QLineEdit that is used to capture keystrokes. It overrides
 * Qt's x11Event to catch raw X11 events and sets them as the text of
 * this widget. The only way to navigate away from this widget when it has
 * focus at the moment is to click on another widget.
 */
class KeyCaptureLine : public QLineEdit {
  // TODO: don't capture TAB, but allow a button for it.
  
public:
  KeyCaptureLine(QWidget* parent);
  
  /**
   * Specifies whether this widget should capture modifiers or not. The
   * modifiers are checked using X11's own IsModifier() functions.
   * @param enable if true, ignores modifiers.
   */
  void ignoreModifiers(bool enable);
  /**
   * Specifies whether this widget should capture regular keys or not. The
   * regular keys are checked using X11's own IsModifier() (but negated).
   * @param enable if true, ignores regular keys.
   */
  void ignoreRegulars(bool enable);
protected:
  bool x11Event(XEvent* event);
  
private:
  bool ignoreMods, ignoreRegs;
};

#endif	/* _CUSTOMWIDGETS_H */

